<template>
	<view class="page">
		<!-- <uni-nav-bar fixed="true" statusBar :border="false" title="首页"></uni-nav-bar> -->
		<!-- 轮播图 -->
		<z-swiper v-model="swiperList" :options="options">
			<z-swiper-item @click="toNotice(item)" :custom-style="{ width: '680rpx', height: '360rpx' }" class="swiper-item"
				v-for="(item, index) in swiperList" :key="index">
				<image :src="item.fileUrl"></image>
			</z-swiper-item>
		</z-swiper>


		<!-- 推荐企业 -->
		<Loading v-if="loading"></Loading>
		<view v-if="indexCompanyList.length" class="enterprise">
			<view class="title">
				<text class="name">推荐企业</text>
				<!-- <text class="more">查看更多</text> -->
			</view>

			<scroll-view scroll-x="true" class="enterprise-list">
				<view  @click="toCompanyDetail(item)" :key="index" v-for="(item, index) in indexCompanyList" class="enterprise-item">
					<image class="img" :src="item.logo"
						mode="aspectFill"></image>
					<view class="tit">{{item.companyName}}</view>
				</view>
			</scroll-view>
		</view>
		<view style="margin-top: 20rpx;">
			<me-tabs :height="80" @change="changeIndex" v-model="tabIndex" :tabs="tabs"></me-tabs>
		</view>
		<view class="course">
			<view class="course-list">
				<view @click="toCompanyDetail(item)" :key="index" v-for="(item, index) in companyList" class="course-item">
					<image class="img" :src="item.logo" mode=""></image>
					<view class="desc">
						<view class="desc-title text-line2">{{ item.companyName }}</view>
						<view class="desc-tag">
							<text>{{ item.proviceName }}</text>
							<text>{{ item.cityName }}</text>
							<text>{{ item.areaName }}</text>
						</view>
					</view>
					<!-- <view class="price">¥299</view> -->
				</view>
				<view v-if="!loading && companyList.length" class="no-more">暂无更多</view>
			</view>
		</view>
		<mescroll-empty v-if="!companyList.length"></mescroll-empty>
	</view>
</template>
<script>
	import {
		getIndexCompany,
		getCompanyList
	} from '@/services/company.js';
	import {
		fetchNoticeDataList
	} from "@/services/notice.js"
	import {
		getCodeList
	} from '@/utils/dict.js'
	export default {
		data() {
			return {
				background: ['color1', 'color2', 'color3'],
				tabs: [],
				tabIndex: 0, // 当前tab的下标
				options: {
					effect: 'coverflow',
					centeredSlides: true,
					slidesPerView: 'auto',
					coverflowEffect: {
						rotate: 40,
						stretch: 0,
						depth: 100,
						modifier: 1,
						slideShadows: true
					}
				},
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				swiperList: [],
				pageNum: 1,
				companyList: [],
				indexCompanyList: [],
				loading: false,
				hasMore: true
			};
		},
		async onLoad() {
			this.getCompanyList();

			uni.getLocation({
				type: 'wgs84',
				success: res => {
					this.getIndexCompany({
						longitude: res.longitude,
						latitude: res.latitude
					});
				}
			});
			const {
				rows
			} = await fetchNoticeDataList({
				"title": "公司"
			});
			this.swiperList = rows;
		},

		onReachBottom() {
			this.getCompanyList();
		},
		methods: {	toNotice({ noticeId }) {
			uni.navigateTo({
				url: '/pages/index/notice/index?id=' + noticeId
			});
		},
			async getIndexCompany(params) {
				const {
					rows
				} = await getIndexCompany({
					pageNum: 1,
					pageSize: 10,
					...params
				});
				this.indexCompanyList = rows;
			},
			changeIndex() {
				this.hasMore = true
				this.pageNum = 1
				this.getCompanyList()
			},
			toCompanyDetail(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/company/detail/index?id='+ item.companyId
				})
			},
			async getCompanyList() {
				if (!this.tabs.length) {
					const tabs = await getCodeList('STU_INDUSTRY');
					this.tabs = [{
						name: '全部',
						value: ''
					}, ...tabs];
				}
				if (!this.hasMore || this.loading) return;
				this.loading = true;
				const {
					rows,
					total
				} = await getCompanyList({
					pageNum: this.pageNum,
					pageSize: 10,
					industry: this.tabs[this.tabIndex].value
				});
				this.companyList = this.pageNum === 1 ? rows : [...this.companyList, ...rows];
				this.pageNum++;
				this.hasMore = this.companyList.length < total;
				this.loading = false;
			}
		}
	};
</script>

<style scoped lang="scss">
	@mixin text-overflow-more($line: 2) {
		white-space: normal;
		overflow: hidden;
		text-overflow: ellipsis;
		text-align: justify;
		display: -webkit-box;
		-webkit-line-clamp: $line;
		-webkit-box-orient: vertical;
	}

	.page {
		background-color: #fefefe;

		.swiper-item {

			// padding: 0 5rpx;
			// overflow: hidden;
			// border-radius: 20rpx;
			// width: 750rpx;
			// height: 350rpx;
			image {
				// margin: 0 30rpx;
				height: 100%;
				width: 100%;
				border-radius: 24rpx;
			}
		}

		/* 分类 */
		.cate-section {
			display: flex;
			justify-content: space-around;
			align-items: center;
			flex-wrap: wrap;
			padding: 30upx 22upx;
			background: #fff;

			.cate-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: $font-sm + 2upx;
				color: $font-color-dark;
			}

			/* 原图标颜色太深,不想改图了,所以加了透明度 */
			image {
				width: 88upx;
				height: 88upx;
				margin-bottom: 14upx;
				border-radius: 50%;
				opacity: 0.7;
				box-shadow: 4upx 4upx 20upx rgba(250, 67, 106, 0.3);
			}
		}

		.course {
			// margin-top: 20rpx;
			padding: 30rpx 30rpx 0;
			background-color: #ffffff;

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 60rpx;
				background-image: url(/static/index/title-bg-3.png);
				background-size: auto 80rpx;
				background-repeat: no-repeat;

				.name {
					padding-left: 10rpx;
					font-size: 36rpx;
					font-weight: 600;
				}

				.more {
					font-size: 28rpx;
					color: #b7bbbf;
				}
			}

			.course-list {
				padding-bottom: 40rpx;

				.course-item {
					border-bottom: 1rpx solid #f8f8f8;
					display: flex;
					align-items: center;
					height: 180rpx;
					margin-top: 20rpx;

					.img {
						height: 180rpx;
						width: 250rpx;
						border-radius: 15rpx;
					}

					.desc {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						height: 130rpx;
						flex: 1;
						margin: 0 20rpx;

						.desc-title {
							font-size: 30rpx;
							color: #2b333b;
						}

						.desc-tag {
							font-size: 28rpx;
							color: #71777d;
						}
					}

					.price {
						display: flex;
						align-items: center;
						justify-content: center;
						width: 120rpx;
						height: 60rpx;
						background: rgba(43, 51, 59, 0.06);
						border-radius: 40rpx;
						font-weight: 500;
						font-size: 30rpx;
						color: #71777d;
					}
				}
			}
		}

		.enterprise {
			background-color: #f9f9f9;
			padding: 30rpx 0 30rpx 30rpx;

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 60rpx;
				background-image: url(/static/index/title-bg-2.png);
				background-size: auto 80rpx;
				background-repeat: no-repeat;

				.name {
					padding-left: 10rpx;
					font-size: 36rpx;
					font-weight: 600;
				}

				.more {
					padding-right: 10rpx;
					font-size: 28rpx;
					color: #b7bbbf;
				}
			}

			.enterprise-list {
				display: flex;
				white-space: nowrap;
				width: 100%;

				.enterprise-item {
					background-color: #ffffff;
					margin-top: 20rpx;
					display: inline-block;
					overflow: hidden;
					border-radius: 20rpx;
					margin-right: 30rpx;
					width: 300rpx;
					height: 420rpx;

					.img {
						width: 100%;
						height: 300rpx;
					}

					.tit {
						white-space: break-spaces;
						padding: 20rpx;
						font-size: 32rpx;
					}
				}
			}
		}
	}
</style>
